#include "StdAfx.h"
#include "BasicApplication.h"


BasicApplication::BasicApplication(HINSTANCE hInst, std::string caption)
	:D3DApp(hInst, caption, D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
	resetCamera();
}


BasicApplication::~BasicApplication(void)
{
}

void BasicApplication::onResetDevice()
{
	resetCamera();	
}

void BasicApplication::resetCamera()
{
	// The aspect ratio depends on the backbuffer dimensions, which can 
	// possibly change after a reset.  So rebuild the projection matrix.
	float w = (float)md3dPP.BackBufferWidth;
	float h = (float)md3dPP.BackBufferHeight;
	gCamera->setLens(D3DX_PI * 0.25f, w/h, 1.0f, 5000.0f);
}

void BasicApplication::updateScene(float dt)
{
	gDInput->poll();
	gCamera->update(dt);
}

void BasicApplication::drawScene()
{
	HR(gd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0f, 0));
	HR(gd3dDevice->BeginScene());

	draw();

	HR(gd3dDevice->EndScene());
	// Present the backbuffer.
	HR(gd3dDevice->Present(0, 0, 0, 0));
}